package com.aaa.controller;

import com.aaa.entity.MyReturn;
import com.aaa.entity.Test_plan;
import com.aaa.service.Test_plan_sasService;
import com.aaa.util.Enum01;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("test_plan_sas")
public class Test_plan_sasController extends BaseController{

    @Autowired
    private Test_plan_sasService plan_sasService;

    MyReturn myReturn=new MyReturn();


    @RequestMapping("toShowSasPlan.do")
    public String toShowUserPage(){
        return "showSasPlan";
    }

    /**
    * @Author: WTH
    * @Description: 查询,分页,计算总条数
    * @Date:2022-07-02 15:05
    * @Params:
    */
    @ResponseBody
    @RequestMapping("selectPlanSas.do")
    public MyReturn selectSasPlan(Test_plan plan_sas){
        Page<Test_plan> page=plan_sasService.selectSasPlan(plan_sas);
        myReturn.setData(page.getResult());
        super.getSuccessResult(myReturn);
        myReturn.setCount(page.getTotal());
        return myReturn;
    }

    /**
    * @Author: WTH
    * @Description: 新增
    * @Date:2022-07-02 16:34
    * @Params:
    */
    @ResponseBody
    @RequestMapping("addPlanSas.do")
    public MyReturn addSasPlan(Test_plan plan_sas){
        plan_sas.setCreate_time(new Date());
        Enum01 enum01 = plan_sasService.addSasPlan(plan_sas);
        myReturn.setCode(enum01.getCode());
        myReturn.setMsg(enum01.getMsg());
        return myReturn;
    }

    /**
    * @Author: WTH
    * @Description: 删除
    * @Date:2022-07-02 16:42
    * @Params:
    */
    @ResponseBody
    @RequestMapping("deletePlanSas.do")
    public MyReturn deleteSasPlan(String id){
        boolean b = plan_sasService.deleteSasPlan(id);
        if(b){
            return super.getSuccessResult(myReturn);
        }else{
            return super.getFailResult(myReturn);
        }
    }

    /**
    * @Author: WTH
    * @Description: 修改
    * @Date:2022-07-02 16:48
    * @Params:
    */
    @ResponseBody
    @RequestMapping("updatePlanSas.do")
    public MyReturn updateSasPlan(Test_plan plan_sas){
        plan_sas.setUpdate_time(new Date());
        Enum01 enum01 = plan_sasService.updateSasPlan(plan_sas);
        myReturn.setCode(enum01.getCode());
        myReturn.setMsg(enum01.getMsg());
        return myReturn;
    }
}
